// pages/ordering/index.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		activeIndex: 0,
		categories: [{
				id: 1,
				name: "特色小吃",
				goodsList: [{
						id: 1,
						name: "小炒肉1",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					},
					{
						id: 2,
						name: "青椒肉丝2",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					}
				]
			},
			{
				id: 1,
				name: "招牌煎饼",
				goodsList: [{
						id: 1,
						name: "小炒肉3",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					},
					{
						id: 2,
						name: "青椒肉丝4",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					}
				]
			},
			{
				id: 1,
				name: "饮品搭档",
				goodsList: [{
						id: 1,
						name: "小炒肉5",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					},
					{
						id: 2,
						name: "青椒肉丝6",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					},
					{
						id: 1,
						name: "小炒肉5",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					},
					{
						id: 2,
						name: "青椒肉丝6",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					},
					{
						id: 1,
						name: "小炒肉5",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					},
					{
						id: 2,
						name: "青椒肉丝6",
						coverUrl: "https://img.yzcdn.cn/vant/cat.jpeg",
						price: 11.00,
						num: 0
					}
				]
			},
		],
		shippingInfo: {
			num: 0
		}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {

	},
	onNavClick: function(e) {
		const index = e.currentTarget.dataset.index;
		console.log(index);
		if (this.activeIndex !== index) {
			this.setData({
				activeIndex: index
			})
		}
	},
	onChange(e) {
		const categoryIndex = e.currentTarget.dataset.categoryIndex;
		const goodsIndex = e.currentTarget.dataset.index;
		const categories = this.data.categories;
		categories[categoryIndex].goodsList[goodsIndex].num = e.detail;
		this.setData({
			categories: categories
		})
	},
	plus(data){
		this.setData({
			"shippingInfo.num" : this.data.shippingInfo.num + 1
		})
	},
	minus(){
		this.setData({
			"shippingInfo.num" : this.data.shippingInfo.num - 1
		})
	}
})
